package com.jereh.topnews.demo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;

import com.jereh.topnews.R;

public class SubMenuActivity extends AppCompatActivity {

    //第一个子菜单
    private int sub_one=0;
    private int sub_one_one=11;
    private int sub_one_two=12;
    private int sub_one_three=13;
    //第二个子菜单
    private int sub_two=1;
    private int sub_two_one=21;
    private int sub_two_two=22;
    private int sub_two_three=23;
    //第三个子菜单
    private int sub_three=2;
    private int sub_three_one=31;
    private int sub_three_two=32;
    private int sub_three_three=33;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sub_menu);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        SubMenu subOne=menu.addSubMenu(Menu.NONE, sub_one, 0, "设置颜色");
        SubMenu subTwo=menu.addSubMenu(Menu.NONE,sub_two,1,"设置字体大小");
        SubMenu subThree=menu.addSubMenu(Menu.NONE,sub_three,2,"设置字体");
        //给子菜单添加选项
        subOne.add(Menu.NONE,sub_one_one,0,"红色");
        subOne.add(Menu.NONE,sub_one_two,1,"蓝色");
        subOne.add(Menu.NONE, sub_one_three, 2, "绿色");
        //给子菜单添加标题
        subOne.setHeaderTitle("请选择颜色");
        //设置字体三级菜单
        SubMenu chineseFont=subTwo.addSubMenu(Menu.NONE,sub_two_one,0,"中文字体");
        SubMenu forFont=subTwo.addSubMenu(Menu.NONE,sub_two_two,1,"外文字体");
        subTwo.setHeaderTitle("请选择字体分类");
        chineseFont.add(Menu.NONE, sub_three_one, 0, "黑体");
        chineseFont.add(Menu.NONE, sub_three_two, 1, "宋体");
        chineseFont.setHeaderTitle("请选择中文字体");
        forFont.add(Menu.NONE, sub_three_three, 0, "Franklin Gothic Book (正文)");
        forFont.setHeaderTitle("请选择外文字体");
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return false;
    }

    @Override
    public void onOptionsMenuClosed(Menu menu) {
        super.onOptionsMenuClosed(menu);
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        return super.onPrepareOptionsMenu(menu);
    }
}
